package top.superflow.flow.config

import org.apache.commons.lang3.StringUtils
import top.superflow.exception.RequestUnsupportedException

object FlowConfigType extends Enumeration{
  
  type InnerFlowConfigTpe = Value
  
  val PROCESS = Value("process")
  
  val FLOW = Value("flow")
  
  val ENTITY = Value("entity")
  
  val RULE = Value("rule")
  
  val MAPPER = Value("mapper")
  
  val RESOURCE = Value("resource")
  
  def getType (strType : String): InnerFlowConfigTpe = {
    val cleanStrType = StringUtils.lowerCase(StringUtils.trim(strType))
    strType match{
      case str if(StringUtils.equalsIgnoreCase(cleanStrType, "process")) => {
        PROCESS
      }
      
      case str if(StringUtils.equalsIgnoreCase(cleanStrType, "flow")) => {
        FLOW
      }
      
      case str if(StringUtils.equalsIgnoreCase(cleanStrType, "entity")) => {
        ENTITY
      }
      
      case str if(StringUtils.equalsIgnoreCase(cleanStrType, "rule")) => {
        RULE
      }
      
      case str if(StringUtils.equalsIgnoreCase(cleanStrType, "mapper")) => {
        MAPPER
      }

      case _ =>{
        throw new RequestUnsupportedException(strType + " is not a supoorted flow type")
      }
    }
  }
}